#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;

#define A 0
#define B 1
#define C 2
#define D 3
int options[4] = {0};
int cur_options[4] = {0};
unordered_multimap<int, int> ophash;
vector<int> answer;
long long ret = 0;
void dfs(int level)
{
    // 剪枝
    int op = answer[level - 1];
    if (options[op] < cur_options[op])
    {
        return;
    }
    if (ophash.count(level - 1))
    {
        int x = level - 1;
        auto range = ophash.equal_range(x);
        for (auto it = range.first; it != range.second; it++)
        {
            int y = it->second;
            if (y < x)
            {
                if (answer[x] != answer[y])
                    return;
            }
        }
    }

    // 判断出口
    if (level == 13)
    {
        ret += 1;
        return;
    }

    for (int i = A; i <= D; i++)
    {
        // if(cur_options[i] + 1 == options[i]) continue; //位置不选，而不是去掉剪枝
        answer[level] = i;
        cur_options[i] += 1;
        dfs(level + 1);
        cur_options[i] -= 1;
    }
}

int m;
int main()
{
    cin >> options[A] >> options[B] >> options[C] >> options[D];
    cin >> m;
    for (int i = 0, a, b; i < m; i++)
    {
        cin >> a >> b;
        ophash.insert({a, b});
        ophash.insert({b, a});
    }
    answer.reserve(15);
    dfs(1);
    cout << ret;
    return 0;
}